package com.concurrent.chapter3.concurrent03;

import java.util.concurrent.Phaser;

public class Main {
	public static void main(String[] args) {
		Phaser phaser = new Phaser(2){
			@Override
			protected boolean onAdvance(int phase, int registeredParties) {
				System.out.println("onAdvance 被" + Thread.currentThread().getName() + "调用 " + System.currentTimeMillis() + " phase value=" + phase + " registeredParties=" + registeredParties);
				return false;
				//返回true 不等待，Phaser呈无效/销毁的状态
				//返回false则Phaser继续工作
			}	
		};
		MyService service = new MyService(phaser);
		ThreadA a = new ThreadA(service);
		a.setName("A");
		a.start();
		ThreadB b = new ThreadB(service);
		b.setName("B");
		b.start();
	}
}
